/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

/**
 * <p>Project: jse2302 - CopyDir_wenti
 * <p>Powered by webrx On 2023-06-29 08:16:50
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class CopyDir_wenti {
    public static void main(String[] args) {
        File bb = new File("C:\\abc\\v11");
        File ad = new File("D:\\v12");

        copyDir(bb, ad);
    }

    public static void copyDir(File src, File dst) {
        if (!src.isDirectory()) {
            return;
        }
        if (dst.exists() && dst.isDirectory()) {
            return;
        }
        dst.mkdirs();
        File[] fs = src.listFiles();
        for (File f : fs) {
            if (f.isDirectory()) {
                //是目录递归调用
                System.out.println(f);
                System.out.println(dst);
                System.out.println(f.getName());
                copyDir(f, new File(dst, f.getName()));
            } else if (f.isFile()) {
                try {
                    var fis = new FileInputStream(f);
                    fis.transferTo(new FileOutputStream(new File(dst, f.getName())));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
